package edu.ccut.saturn.workflow.delegate;

import java.sql.Connection;
import java.util.ArrayList;

import edu.ccut.saturn.component.DefaultComponent;
import edu.ccut.saturn.component.IParameterContext;
import edu.ccut.saturn.component.SaturnData;
import edu.ccut.saturn.operation.Operation;
import edu.ccut.saturn.workflow.common.Constants;

public class QueryDelegateByUseridAndItemid extends DefaultComponent {
	@Override
	public void execute(IParameterContext parameterContext) throws Exception {
		String workitemid = (String)parameterContext.getParameterValue(0);
		String delegateid = null;
		Connection conn = parameterContext.getConnection();
		String sql = "select * from wf_delegate where workitem_id="+workitemid
				  +" and state ='"+Constants.DELEGATE_STATE_RUNNING+"' and delegate_type='"+Constants.WORKITEM_BIZSTATE_HELP+"'";
		ArrayList<SaturnData>  delegateInstList = Operation.dataBase().queryBySQL(Constants.SATURNDATA_WF_DELEGATE,
				sql, conn);
		if(delegateInstList!=null){
			SaturnData delegateInst = delegateInstList.get(0);
			delegateid = delegateInst.get("delegate_id")+"";
		}
		parameterContext.setParameter(1, delegateid);
	}
}